@extends('admin.layout')
@section('title')
  管理员列表
@endsection
@section('body')
    <div class="widget-body">
        <form role="form" class="form-inline widget">
            <div class="form-group">
                <input type="text" name="username" placeholder="用户名" class="form-control" value="{{$username}}">
            </div>
            <button class="btn btn-default" type="submit">搜索</button>
            <button class="btn btn-default" type="button" onclick="location.href='{{action(NAMESPACE_ADMIN.'AdminController@getAdd')}}';">添加</button>
        </form>
        <div class="widget">
            <table class="table table-bordered table-hover">
                <thead>
                <tr>
                    <th>用户名</th>
                    <th>邮箱</th>
                    <th>所属角色</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $key=>$item)
                    <tr>
                        <td>{{$item['name']}}</td>
                        <td>{{$item['email']}}</td>
                        <td>{{$item['rolename']}}</td>
                        <td>@if($item['status']==1) 正常 @else 禁用  @endif</td>
                        <td>
                            @if($item['status']==1) <a href="#" status="0" id="{{$item['id']}}" class="changeStatus">禁用</a> @else <a href="#" status="1" id="{{$item['id']}}" class="changeStatus">启用</a> @endif
                            | <a href="{{action(NAMESPACE_ADMIN.'AdminController@getChangeRole',['id'=>$item['id']])}}">修改角色</a>
                            | <a href="#"
                                 onclick="if(confirm('您确认删除?')) location.href = '{{action(NAMESPACE_ADMIN.'AdminController@getDel',['id'=>$item['id']])}}';"
                            >删除</a>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        <div class="widget">
            <div class="pull-left">共{{ $data->total() }}条记录</div>
            <div class="pull-right">{!! $data->appends($username)->render() !!}</div>
            <div style="clear: both"></div>
        </div>
    </div>
 </div>
@endsection
@section('foot_script')
 <script type="text/javascript">
  $(".changeStatus").click(function () {
    var status = $(this).attr('status');
    var id = $(this).attr('id');
    $.ajax({
      url:'{{action(NAMESPACE_ADMIN.'AdminController@getChange')}}',
      type:'get',
      dataType:'json',
      data:{'status':status,'id':id},
      success:function(data){
         if(data.code == 200){
            location.reload();
         }
      },
      error:function(){

      }
    });
  });
 </script>
@endsection